package com.wanli.agent.homepage.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wanli.agent.R;
import com.wanli.agent.bean.IncomeListBean;
import com.wanli.agent.utils.DateTimeUtil;
import com.wanli.agent.utils.NumberFormatUtils;

import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: HWC
 * Description: 服务商列表
 */
public class ShareIncomeListNewAdapter extends RecyclerView.Adapter<ShareIncomeListNewAdapter.ViewHolder> {

    private List<IncomeListBean.DataBean.ItemListBean> listsBeans;
    private Context context;

    public ShareIncomeListNewAdapter(List<IncomeListBean.DataBean.ItemListBean> listsBeans) {
        this.listsBeans = listsBeans;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        context = viewGroup.getContext();
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_share_income_new_list, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(inflate);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        IncomeListBean.DataBean.ItemListBean dataBean = listsBeans.get(position);
        holder.tvTime.setText(DateTimeUtil.format7(new Date(Long.parseLong(dataBean.getCreate_time()) * 1000)));
        String money = NumberFormatUtils.formatTwoDecimal(Double.parseDouble(dataBean.getMoney()) / 100);
        holder.tvMoney.setText(money + "元");
        holder.tvRemark.setText("备注：" + dataBean.getRemark());
        //1微信支付 2支付宝支付 3银联云闪付 5NFC 6刷卡交易

        if (dataBean.getRelation_type() == 1) {
            holder.tvRelationType.setText("交易分润");
        } else if (dataBean.getRelation_type() == 2) {
            holder.tvRelationType.setText("提现奖励");
        } else if (dataBean.getRelation_type() == 3) {
            holder.tvRelationType.setText("激活返现");
        } else if (dataBean.getRelation_type() == 4) {
            holder.tvRelationType.setText("挂靠奖励");
        } else if (dataBean.getRelation_type() == 9) {
            holder.tvRelationType.setText("交易分润");
        } else {
            holder.tvRelationType.setText("");
        }
    }

    @Override
    public int getItemCount() {
        return listsBeans.size() == 0 ? 0 : listsBeans.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.tv_money)
        TextView tvMoney;
        @BindView(R.id.tv_relation_type)
        TextView tvRelationType;
        @BindView(R.id.tv_remark)
        TextView tvRemark;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
